home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / DIZZY / SRC / FILESEL.C < prev    next >
Text File  |  1990-12-29  |  2KB  |  100 lines

  1. /*
  2. >>    This file handles a file selection box for xdizzy
  3. >>
  4. >>    Copyright 1990 Juri Munkki, all rights reserved
  5. >>
  6. >>    Please read the included file called "DizzyDoc" for information on
  7. >>    what your rights are concerning this product.
  8. >>
  9. */
  10.  
  11. #include "dizzy.h"
  12. #ifndef MACINTOSH
  13. #include "xstuff.h"
  14. #include <Xm/FileSB.h>
  15. #include <X11/Shell.h>
  16.  
  17. static    Widget    MyFileSel;            /*    The file selection widget.        */
  18. static    int     StopFileSelect=0;    /*    True, when user has responded.    */
  19. static    Widget    top2;                /*    MyFileSel top level widget.        */
  20.  
  21. /*
  22. >>    User clicked ok, and this callback was called.
  23. */
  24. void    DoOk(w,ignore,calldata)
  25. Widget                        w;
  26. char                        *ignore;
  27. XmFileSelectionBoxCallbackStruct    *calldata;
  28. {
  29.     StopFileSelect= -2;
  30.     strncpy(DestFileName,XmTextGetString(
  31.                          XmFileSelectionBoxGetChild(
  32.                           MyFileSel,XmDIALOG_TEXT)),
  33.                           MAXFILENAME-1);
  34.     XtUnmapWidget(top2);
  35.     XFlush(Disp);
  36.     MainDisable=0;
  37. }
  38.  
  39. /*
  40. >>    User clicked cancel, and this callback was called.
  41. */
  42. void    DoCancel(w,ignore,calldata)
  43. Widget                        w;
  44. char                        *ignore;
  45. XmFileSelectionBoxCallbackStruct    *calldata;
  46. {
  47.     StopFileSelect= -1;
  48.     XtUnmapWidget(top2);
  49.     XFlush(Disp);
  50.     MainDisable=0;
  51. }
  52. /*
  53. >>    Create a file selection widget.
  54. */
  55. void    InitFileSelection()
  56. {
  57.     top2=XtCreateApplicationShell("FileSel",topLevelShellWidgetClass,NULL, 0);
  58.     MyFileSel=XmCreateFileSelectionBox(top2,"MyFileSel",Wargs,0);
  59.  
  60.     XtAddCallback(MyFileSel, XmNokCallback, DoOk, 0L);
  61.     XtAddCallback(MyFileSel, XmNcancelCallback, DoCancel, 0L);
  62.     XtUnmanageChild(XmFileSelectionBoxGetChild(MyFileSel,XmDIALOG_HELP_BUTTON));
  63.     XtManageChild(MyFileSel);
  64.     XtRealizeWidget(top2);
  65. }
  66.  
  67. static    int     needsinit= -1;    /*    Has the above routine been called?    */
  68.  
  69. /*
  70. >>    DestFileName is changed to reflect the file name the user chose.
  71. >>    Returns true, if the user didn't cancel.
  72. */
  73. int     DoFileSelection()
  74. {
  75.     if(needsinit)    InitFileSelection();
  76.     else            XtManageChild(MyFileSel);
  77.  
  78.     MainDisable= -1;
  79.     StopFileSelect=0;
  80.     XmTextSetString(XmFileSelectionBoxGetChild(MyFileSel,XmDIALOG_TEXT),DestFileName);
  81.  
  82. #ifdef    RESETFILTER
  83.     XmTextSetString(XmFileSelectionBoxGetChild(MyFileSel,XmDIALOG_FILTER_TEXT),"./*");
  84. #endif
  85.  
  86.     if(needsinit)    needsinit=0;
  87.     else            XtMapWidget(top2);
  88.  
  89.     do
  90.     {    if(XtPending())
  91.         {    XtNextEvent(&MyEvent);
  92.             XtDispatchEvent(&MyEvent);
  93.         }
  94.     } while(!StopFileSelect);
  95.     
  96.     XtUnmanageChild(MyFileSel);
  97.     return (StopFileSelect == -2);
  98. }
  99. #endif
  100.